<?php
namespace App\Common\Cla\ClaBase\Traits\Common\MagicCall;

use App\Common as com;
use think\facade\App;

/**
 * 类通用方法->魔术方法->__call
 *
 * @property array $magicCall_GetAllow 允许读的属性。格式[ 'msgSaltKey', ... ]
 * @property array $magicCall_SetAllow 允许写的属性。格式[ 'msgSaltKey', ... ]
 */
trait Get {
	
	/**
	 * 魔术方法->call->get(处理属性读写)
	 * @param str $name 方法名
	 * @param array $arguments 参数
	 * @return mixed||Exception 返回数据(如无法处理则抛出异常:com\Cla\Err\Code::$sysDataErrorSeverity)
	 */
	protected function __magicCallOfGet( $name, $arguments )
	{
		// 取出属性名
		$propertyName = substr( $name, 3 );
		$propertyName = com\Lib\Fun\Str::parseName( $propertyName, 1, false );
		// 检查可以读的属性
		if( ! in_array( $propertyName, $this->magicCall_GetAllow ?? [] ) ){
			throw com\Lib\Err\Exception::makeOfNew( '', com\Cla\Err\Code::$sysDataErrorSeverity );
		}
		// 读取属性值
		if( isset( $this->$propertyName ) ){
			return $this->$propertyName;
		}else{
			throw com\Lib\Err\Exception::makeOfNew( '', com\Cla\Err\Code::$sysDataErrorSeverity );
		}
	}
}
